<template>
    <div class="login">
        <div class="form_container">
            <span class="title">扶贫产品推广系统</span>
            <el-form :model="eleForm" :rules="eleFormRules" ref="eleForm" label-width="51px" class="loginForm" @keyup.enter.native="submit">
                <el-form-item label="账号" prop="accunt">
                    <el-input v-model.trim="eleForm.accunt" style="width:300" palceholder="请输入账号"></el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password">
                    <el-input v-model.trim="eleForm.password" palceholder="请输入密码" type="password"></el-input>
                </el-form-item>
                <el-button type="primary" @click="submit">注册</el-button>
            </el-form>
        </div>
    </div>
</template>
<script>
// 全部导入
import api from '@/api/others'
export default {
    data() {
        return {
            // 登录表单
            eleForm:{
                accunt:'',                      //账号
                password:'',                    //密码
            },
            // 登录规则
            eleFormRules:{
                accunt:[
                    {required:true,message:'账号不能为空',trigger:'blur'},
                    {min:4,max:30,message:'长度在4到30个字符之间',trigger:'blur'}
                ],
                password:[
                    {required:true,message:'密码不能为空',trigger:'blur'},
                    {min:4,max:30,message:'长度在4到30个字符之间',trigger:'blur'}
                ],
            },
        }
    },
    methods: {
        submit(){
            this.$refs.eleForm.validate(valid=>{
                if (!valid) return
                api.register(this.eleForm).then(res=>{
                    if(res.code !== 200) return
                    // console.log(res)
                    this.$message.success('注册成功！即将跳转登录页面！')
                    // 这里得清空token，不然可能会直接跳转到首页
                    localStorage.removeItem('tokenKey')
                    localStorage.removeItem('by_menu')
                    // 跳转
                    this.$router.push('/login')
                })
            })
        }
    },
    created() {
        
    },
    mounted() {
        
    },
}
</script>
<style lang="less" scoped>
.login {
    position: relative;
    width: 100%;
    height: 100%;
    background: url(../assets/img/bg.jpg) no-repeat center center;
    background-size: 100% 100%;
    .form_container {
        width: 370px;
        height: 380px;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        border-radius: 5px;
        text-align: center;
        .title{
            font-family: "Microsoft YaHei";
            font-weight: bold;
            font-size: 26px;
            color: #fff;
        }
        .loginForm{
            position: relative;
            margin-top: 10px;
            padding: 20px 24px 20px 20px;
            background: rgba(165, 160, 160, 0.09);
            border-radius: 5px;
            /deep/ .el-button--primary {
                margin-top: 30px;
                min-width: 150px;
            }
            /deep/ .el-form-item{
                position: relative;
                margin-bottom: 50px;
                /deep/ .el-form-item__content {
                    position: absolute;
                    top: 40px;
                    left: -50px;
                    width: 330px;
                }
            }
        }
    }
}
</style>